import {post} from "@/utils/http.js";
import {rsaPubEncrypt} from "@/utils/EncryptUtils.js";
import useAccountStore from "@/store/modules/AccountStore.js";
import {elMessageTip} from "@/utils/MessageTipUtils.js";
import {resolvePromise_status} from "@/utils/ReturnUtils.js";
import {genDesKey} from "@/utils/EncryptUtils.js";
import request from "@/utils/request.js";
import {desDecrypt} from "@/utils/EncryptUtils.js";
import {resolvePromise_data} from "@/utils/ReturnUtils.js";

export const liuAPI = (content, img) => {
    return post(
        '/liu/add',
        {
            account: rsaPubEncrypt(useAccountStore().account),
            userId: useAccountStore().user.id,
            content: rsaPubEncrypt(content),
            img
        }
    ).then(
        res => {
            elMessageTip(res)
            return resolvePromise_status(res)
        }
    )
}

export const getLiuPageAPI = (current, pageSize, userId = null, kw = null) => {
    const desKey = genDesKey()
    return request.get(
        '/liu/page',
        {
            params: {
                desKey: rsaPubEncrypt(desKey),
                current, pageSize, userId,
                kw: kw === null ? null : rsaPubEncrypt(kw),
            }
        }
    ).then(
        res => {
            res = desDecrypt(res, desKey)
            // elMessageTip(res)
            return resolvePromise_data(res)
        }
    )
};

export const delLiuById = (id) => {
    return post(
        `/liu/del`,
        {
            account: rsaPubEncrypt(useAccountStore().account),
            id
        }
    ).then(
        res => {
            elMessageTip(res)
            return resolvePromise_status(res)
        }
    )
}